$().ready(function() {
	validateRule();
});


$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});
function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/shop/item/save",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(r) {
			if (r.code == 0) {
				parent.layer.msg(r.msg);
                returnList();
			} else {
				parent.layer.alert(r.msg)
			}
		}
	});
}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
            title : "required",
            price : "required",
            num : "required",
            cName : "required",
            cid : "required",
            image : "required"
		},
		messages : {
            title : "请填商品标题",
            price : "请填商品价格",
            num : "请填库存数量",
            cName : "请选择商品类目",
            cid : "找不到商品类目id",
            image : "请填商品图片url"
		}
	});
}
var openDept = function(){
    layer.open({
        type:2,
        title:"选择类目",
        area : [ '400px', '600px' ],
        content:"/shop/category/treeView"
    })
};
function loadCategory( cId,cName){
    $("#cid").val(cId);
    $("#cName").val(cName);
}
function returnList() {
	var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
	parent.layer.close(index);
}